#include "ScnsKey.c.h"

#if defined(SCNS_KEY_ENABLE)&&SCNS_KEY_ENABLE==1

#include "ScnsMenu.h"
#include "ScnsTm1638.h"

static void callback(ScnsKeyMsg key)
{
    if(key.key>=SCNS_KEY_K1&&key.key<=SCNS_KEY_K16)
    {
        if(key.status==SCNS_KEY_PRESS_DOWN)
            scnsTm1638DisplayPartial(SCNS_TM1638_1,(const uint8[2]){key.key-SCNS_KEY_K1,0XFF},0,2);
        else if(key.status==SCNS_KEY_PRESS_HOLD||key.status==SCNS_KEY_PRESS_HOLD_DOWN)
        {
            scnsTm1638SetBright(SCNS_TM1638_1,(key.key-SCNS_KEY_K1)&0X7);
            scnsTm1638DisplayPartial(SCNS_TM1638_1,(const uint8[2]){key.key-SCNS_KEY_K1+0x10,0XFF},0,2);
        }
        else if(key.status==SCNS_KEY_PRESS_UP)
            scnsTm1638DisplayPartial(SCNS_TM1638_1,(const uint8[2]){0XFF,0XFF},0,2);
    }
}

const ScnsBspKeyConfig scnsBspKeyConfig[SCNS_KEY_MAX]={
    {.name="S1",.callbacks=(void (*[])(ScnsKeyMsg)){scnsMenuHandleKey,NULL}},
    {.name="S2",.callbacks=(void (*[])(ScnsKeyMsg)){scnsMenuHandleKey,NULL}},
    {.name="S3",.callbacks=(void (*[])(ScnsKeyMsg)){scnsMenuHandleKey,NULL}},
    {.name="S4",.callbacks=NULL},
    
    {.name="K1",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K2",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K3",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K4",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K5",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K6",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K7",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K8",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K9",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K10",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K11",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K12",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K13",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K14",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K15",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
    {.name="K16",.callbacks=(void (*[])(ScnsKeyMsg)){callback,NULL}},
};

ScnsStatus scnsBspKeyInit(void)
{
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspKeyPostInit(void)
{
    return SCNS_STATUS_OK;
}

#endif